﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Windows.Forms;

namespace WorkWeiXin.Winforms
{
    static class RuntimeConfig
    {
        public static void WriteJson(string json, string appName)
        {
            string time = DateTime.Now.ToString();

            var filename = appName + ".tmp";
            File.WriteAllText(filename,
                string.Format("【{0}】【{1}】", time, json));
        }

        static readonly char[] separator = new char[] { '【', '】' };
        public static string ReadJson(out DateTime time, string appName)
        {
            var filename = appName + ".tmp";

            string content = File.ReadAllText(filename);
            string[] parts = content.Split(separator, StringSplitOptions.RemoveEmptyEntries);

            time = DateTime.Parse(parts[0]);

            return parts[1];
        }


        public static readonly string configFilename = "work.weixin.config";


    }
}
